package cn.edu.nju.software.servlet.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.nju.software.model.user.Information;

/**
 * Servlet implementation class ChangeInformationServlet
 */
public class ChangeInformationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		PrintWriter writer = response.getWriter();
		String message = "";
		String reload = "";
		request.setCharacterEncoding("UTF-8");
		
		String username = (String) getServletContext().getAttribute("username");
		String gender = request.getParameter("gender");
		String age = request.getParameter("age");
		
		Information information = new Information();
		information.updateInformation(username, gender, age);
		
		message = "sucess!";
		reload = "user/information.jsp";
		
		writer.println("<script>alert('" + message + "');"
					+ "window.location.href='" + reload + "';</script>");
	}

}
